package com.kaibes.web.response;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.context.annotation.Configuration;

@Configuration
public class ResponseConfig {

    private Map<Integer, StatusBody> statusBodyMap = new HashMap<>();
    {
        StatusBody body = new StatusBody();
        body.setMessage("请求不正确");
        statusBodyMap.put(HttpServletResponse.SC_BAD_REQUEST, body);
        body = new StatusBody();
        body.setMessage("您没有登录，或者登录已过期");
        statusBodyMap.put(HttpServletResponse.SC_UNAUTHORIZED, body);
        body = new StatusBody();
        body.setMessage("您没有权限使用");
        statusBodyMap.put(HttpServletResponse.SC_FORBIDDEN, body);
        body = new StatusBody();
        body.setMessage("查找不到目标文件或接口(%s:%s)");
        body.setRedirect(null);
        statusBodyMap.put(HttpServletResponse.SC_NOT_FOUND, body);
        body = new StatusBody();
        body.setMessage("请求超时，请刷新当前页面并重试");
        body.setRedirect(null);
        statusBodyMap.put(HttpServletResponse.SC_REQUEST_TIMEOUT, body);
        body = new StatusBody();
        body.setMessage("系统出现错误，请联系开发商");
        body.setRedirect(null);
        statusBodyMap.put(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, body);
    }
    
    public ResponseConfig putStatusBody(Integer key, StatusBody statusBody) {
        statusBodyMap.put(key, statusBody);
        return this;
    }

    public Map<Integer, StatusBody> getStatusBodyMap() {
        return statusBodyMap;
    }
    
}
